﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using eMeng;
using ValidityCheck;
using JavaScript;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
       InitMenu();

    }
    protected void Login_Click(object sender, EventArgs e)
    {
        if (Check.IsNull(UserName.Text))
        {
            JSDialog.Alert(this, "用户名为空！");
        }
        else if (Check.IsNull(Password.Text))
        {
            JSDialog.Alert(this, "密码为空！");
        }
        else
        {
           
            SymmCrypto sc = new SymmCrypto(SymmCrypto.SymmProvEnum.DES);
            string password = sc.Encrypting(Password.Text, "binhai");
            UserInfo userInfo = new UserInfo();
            userInfo.UserName = UserName.Text.Trim();
            userInfo.Password = password;
            if (SQL.SQLHelper.IsExist(userInfo))
            {
                Session.Add("admin", "true");
                Response.Redirect("Admin/Admin_Notice.aspx");
            }
            else
            {
                JSDialog.Alert(this, "用户名密码不存在！");
            }


        }

    }

    protected void Password_TextChanged(object sender, EventArgs e)
    {
        
        Login_Click(sender, e);   

    }
    protected void UserName_TextChanged(object sender, EventArgs e)
    {

    }


    protected void InitMenu()
    {

        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        MainMenu.Items.Clear();
        MenuItem MainPage = new MenuItem();
        MainPage.Enabled = true;
        MainPage.Selectable = true;
        MainPage.Selected = false;
        MainPage.Value = MainPage.ToolTip = MainPage.Text = "首页";
        MainPage.NavigateUrl = "Default.aspx";
        MainMenu.Items.Add(MainPage);
        var Menus = from menu in dc.Menus
                       select new
                       {
                           MenuItem_id = menu.MenuItem_id,
                           MenuItem_Name = menu.MenuItem_Name
                       };
        foreach (var menu in Menus)
        {
                MenuItem menuitem = new MenuItem();
                menuitem.Enabled = true;
                menuitem.Selectable = true;
                menuitem.Selected = false;
                menuitem.ToolTip = menuitem.Text = menu.MenuItem_Name.Trim();
                menuitem.Value = menu.MenuItem_id.ToString();
                if (menu.MenuItem_id == 2)
                {
                    menuitem.NavigateUrl = "http://binhai.nankai.edu.cn/script/binhai/CollegeLeaderPage.htm";
                }
                else if (menu.MenuItem_id == 3)
                {
                    menuitem.NavigateUrl = "OrgnizationList.aspx";
                }
                else if (menu.MenuItem_id == 4)
                {
                    menuitem.NavigateUrl = "RuleList.aspx";
                }
                else if (menu.MenuItem_id == 5)
                {
                    menuitem.NavigateUrl = "MeetingList.aspx";
                }
                else if (menu.MenuItem_id == 6)
                {
                    menuitem.NavigateUrl = "CollegeConditionList.aspx";
                }
                else if (menu.MenuItem_id == 7)
                {
                    menuitem.NavigateUrl = "LawList.aspx";
                }
                else if (menu.MenuItem_id == 8)
                {
                    menuitem.NavigateUrl = "ResourceOnline.aspx";
                }
                MainMenu.Items.Add(menuitem);
        }
        dc.Dispose();
    }
}
